package com.sh.data.engine.domain.datadev.offline.model.enums;

import java.util.Objects;

/**
 * @Author: zigui.zdf @Date: 2022/2/14 14:02:44 @Description:
 */
public enum OfflineDevNodeTypeEnum {
    DIR_NORMAL(0, "普通目录"),
    DIR_OF_DATADEV(23, "离线开发目录"),
    DIR_OF_SYNCTASK(24, "离线同步目录"),
    DIR_OF_DATAQUALITY(25, "数据质量目录"),

    DIR_TASK_FLOW(1, "工作流程"),
    DIR_DATAINTEGRATION(2, "数据集成"),
    DIR_DATADEV(3, "数据开发"),
    DIR_DATAQUALITY(4, "数据质量"),

    RESOURCE(10, "资源"),
    FUNCTION(11, "函数"),
    VNODE_START(12, "开始节点"),
    SQL(13, "SQL"),
    MR(14, "MapReduce"),
    IMPALA(15, "Impala"),
    SHELL(16, "Shell"),
    PYTHON2(17, "Python2"),
    PYTHON3(18, "Python3"),
    PYSPARK(19, "Pyspark"),
    OFFLINE(20, "离线同步"),
    API(21, "接口采集"),
    DATAQUALITY(22, "数据质量");

    private Integer nodeType;

    private String nodeDesc;

    OfflineDevNodeTypeEnum(Integer nodeType, String nodeDesc) {
        this.nodeType = nodeType;
        this.nodeDesc = nodeDesc;
    }

    public Integer getNodeType() {
        return nodeType;
    }

    public String getNodeDesc() {
        return nodeDesc;
    }

    public boolean isNormalDir() {
        if (this.equals(DIR_NORMAL)) {
            return true;
        }
        return false;
    }

    public boolean isDir() {
        switch (this) {
            case DIR_NORMAL:
            case DIR_TASK_FLOW:
            case DIR_DATAINTEGRATION:
            case DIR_DATADEV:
            case DIR_DATAQUALITY:
            case DIR_OF_DATADEV:
            case DIR_OF_DATAQUALITY:
            case DIR_OF_SYNCTASK:
                return true;
            default:
                return false;
        }
    }

    public boolean isTaskFlowDefaultDir() {
        switch (this) {
            case DIR_DATAINTEGRATION:
            case DIR_DATADEV:
            case DIR_DATAQUALITY:
                return true;
            default:
                return false;
        }
    }

    public boolean isTask() {
        switch (this) {
            case VNODE_START:
            case SQL:
            case MR:
            case IMPALA:
            case SHELL:
            case PYTHON2:
            case PYTHON3:
            case PYSPARK:
            case OFFLINE:
            case API:
            case DATAQUALITY:
                return true;
            default:
                return false;
        }
    }

    public boolean isDataintegrationTask() {
        switch (this) {
            case OFFLINE:
            case API:
                return true;
            default:
                return false;
        }
    }

    public boolean isDatadevTask() {
        switch (this) {
            case SQL:
            case MR:
            case IMPALA:
            case SHELL:
            case PYTHON2:
            case PYTHON3:
            case PYSPARK:
                return true;
            default:
                return false;
        }
    }

    public boolean isDataqualityTask() {
        switch (this) {
            case DATAQUALITY:
                return true;
            default:
                return false;
        }
    }

    public boolean isUnitTask() {
        switch (this) {
            case DIR_NORMAL:
            case DIR_TASK_FLOW:
                return true;
            default:
                return false;
        }
    }

    public boolean isUnitTaskPlus(Integer nodeType) {
        if (nodeType.equals(DIR_DATAINTEGRATION.getNodeType()) && this.equals(DIR_OF_SYNCTASK)) {
            return true;
        }
        if (nodeType.equals(DIR_DATADEV.getNodeType()) && this.equals(DIR_OF_DATADEV)) {
            return true;
        }

        if (nodeType.equals(DIR_DATAQUALITY.getNodeType()) && this.equals(DIR_OF_DATAQUALITY)) {
            return true;
        }
        switch (this) {
            case DIR_NORMAL:
            case DIR_TASK_FLOW:
                return true;
            default:
                return false;
        }
    }

    public boolean isDataAssetTask() {
        switch (this) {
            case RESOURCE:
            case FUNCTION:
            case SQL:
            case MR:
            case IMPALA:
            case SHELL:
            case PYTHON2:
            case PYTHON3:
            case PYSPARK:
            case OFFLINE:
            case API:
            case DATAQUALITY:
                return true;
            default:
                return false;
        }
    }

    public static OfflineDevNodeTypeEnum of(Integer nodeType) {
        for (OfflineDevNodeTypeEnum nodeTypeEnum : OfflineDevNodeTypeEnum.values()) {
            if (Objects.equals(nodeTypeEnum.nodeType, nodeType)) {
                return nodeTypeEnum;
            }
        }
        return null;
    }
}
